package com.EAIPClub.ClassesManager.service.impl;

import com.EAIPClub.ClassesManager.mapper.ClassesFileInfoMapper;
import com.EAIPClub.ClassesManager.service.ClassesFileInfoManagerService;
import com.api.POJO.ClassesManager.ClassesFileInfo;
import com.api.POJO.ClassesManager.ClassesManagerReturnMsg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description :
 * @Author :
 * @Date : 2021/12/12
 */
@Service
@Slf4j
public class ClassesFileInfoManagerServiceImpl implements ClassesFileInfoManagerService {

    private ClassesFileInfoMapper mapper;

    @Autowired
    public void setMapper(ClassesFileInfoMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public ClassesManagerReturnMsg addNewClassesFileInfo(ClassesFileInfo info) {
        ClassesManagerReturnMsg returnMsg = new ClassesManagerReturnMsg();
        List<String> Msg = new ArrayList<>();
        log.info("即将添加新的课程文件信息.info:{}",info);
        if (info == null){
            log.warn("检测到课程文件内容为空!");
            returnMsg.setStatus(500);
            Msg.add("检测到课程文件内容为空!");
            returnMsg.setMsg(Msg);
            return returnMsg;
        }
        Boolean aBoolean = mapper.addNewClassesFileInfo(info);
        if (!aBoolean){
            log.warn("将课程文件信息加入到数据库失败!");
            returnMsg.setStatus(500);
            Msg.add("将课程文件信息加入到数据库失败!");
            returnMsg.setMsg(Msg);
            return returnMsg;
        }
        log.info("添加新的课程文件信息成功.info:{}",info);
        returnMsg.setStatus(200);
        returnMsg.setMsg(Msg);
        return returnMsg;
    }

    @Override
    public ClassesManagerReturnMsg getClassesFileInfoByClassesUid(String classUid) {
        ClassesManagerReturnMsg returnMsg = new ClassesManagerReturnMsg();
        List<String> Msg = new ArrayList<>();
        log.info("即将通过课程uid查找课程文件信息.classesuid:{}",classUid);
        if (classUid==null || classUid.equals("")){
            log.warn("检测到课程uid为空!");
            returnMsg.setStatus(500);
            Msg.add("检测到课程uid为空!");
            returnMsg.setMsg(Msg);
            return returnMsg;
        }
        ClassesFileInfo classesFileInfoByClassUid = mapper.getClassesFileInfoByClassUid(classUid);
        if (classesFileInfoByClassUid == null){
            log.warn("未能通过课程uid找到课程文件信息!uid:{}",classUid);
        }
        log.info("通过课程uid查找课程文件信息完毕.");
        returnMsg.setStatus(200);
        returnMsg.setMsg(Msg);
        returnMsg.setFileInfo(classesFileInfoByClassUid);
        return returnMsg;
    }

    @Override
    public ClassesManagerReturnMsg deleteClassesFileInfoByClassesUid(String classUid) {
        ClassesManagerReturnMsg returnMsg = new ClassesManagerReturnMsg();
        List<String> Msg = new ArrayList<>();
        log.info("即将通过课程uid删除课程文件信息.uid:{}",classUid);
        if (classUid == null || classUid.equals("")){
            log.warn("检测到课程uid为空!");
            returnMsg.setStatus(500);
            Msg.add("检测到课程uid为空!");
            returnMsg.setMsg(Msg);
            return returnMsg;
        }
        Boolean aBoolean = mapper.deleteClassesFileInfoByClassesUid(classUid);
        if (!aBoolean){
            log.warn("通过课程uid删除课程文件信息失败!");
            returnMsg.setStatus(500);
            Msg.add("通过课程uid删除课程文件信息失败!");
            returnMsg.setMsg(Msg);
            return returnMsg;
        }
        log.info("通过课程uid删除课程文件信息成功.");
        returnMsg.setStatus(200);
        returnMsg.setMsg(Msg);
        return returnMsg;
    }
}
